home *** CD-ROM | disk | FTP | other *** search
File List | 1991-02-17 | 14.3 KB | 332 lines |
- Turbo Assembler Version 2.0 02/17/91 12:40:52 Page 1
- criterr.asm
- CRITERR.ASM
- TRAP CRITICAL ERRORS FROM W/IN C
-
- 1
- 2
- 3 ; MODULE CRITERR.ASM
- 4 ; JANUARY 1991
- 5 ; PETER HYMAN (609) 799-2638
- 6 ; 148 TENNYSON DRIVE
- 7 ; PLAINSBORO, NJ 08536
- 8
- 9 ; MODIFIED 2/16/91 SEE NOTES AT END OF SOURCE FOR DESCRIPTION OF CHANGES
- 10
- 11 ;;;;; TWO FUNCTIONS ;;;;;
- 12
- 13 ; FUNCTION NAME: CRITERR( ONOFF )
- 14 ; INPUTS 1 = TRAP CRITICAL ERRORS, 0 TURN OFF TRAP
- 15 ; RETURNS 0 IF SUCCESSFUL, 1 IF ALREADY INSTALLED
- 16
- 17 ; FUNCTION NAME: CLRCRITERR( )
- 18 ; CLEAR CRITICAL ERROR VARIABLES
- 19
- 20 ; ON CRITICAL ERRORS, INT 24H HANDLER WILL RETURN AN IGNORE CODE TO DOS
- 21 ; IF VERSION < 3, OR A FAIL CODE FOR DOS >= 3
- 22 ; IF VERSION >= 3, DOS FUNCTION 59H IS CALLED ALSO, AND EXTENDED ERROR
- 23 ; INFO IS ALSO PUT INTO STRUCTURE
- 24
- 25 ;;;;; USES SIMPLIFIED SEGMENT DIRECTIVES. ASSEMBLE WITH I8086S, M, C OR L
- 26 ;;;;; DEFINED
- 27
- 28 ;;;;; ASSEMBLE AS MASM/TASM /mx /dI8086[S|M|C|L] criterr;
- 29 ;;;;; TURBO ASSEMBLER YIELDS SMALLER CODE WITH /Q OPTION
- 30
- 31 0000 .MODEL LARGE
- 32 = 0006 p equ 6
- 33 = 0001 LCODE EQU 1
- 34 = 0001 LDATA EQU 1
- 35
- 36 ;;;;; FORMAT FOR CRITICAL ERROR HEADER BLOCK ;;;;;
- 37 ;;;;; CERTAIN CHAR VARIABLES EXPANDED TO INT FOR PROPER ALLIGNMENT ;;;;;
- 38 *000 CERR STRUC ; critical error structure
- 39 *000 01*(??) ceflag db ? ; flag to indicate critical error 1 = yes
- 40 *001 01*(??) cerrno db ? ; critical error number ; 2/16/91 changed to byte
- 41 *002 01*(????) cerrtype dw ? ; critical error type/action/drive, AX
- 42 *004 01*(??) drive db ? ; drive letter as a char
- 43 *005 01*(??) read_wr db ? ; read or write error 1 = write
- 44 *006 01*(??) disk_area db ? ; area of error, 0 = dos area, 1 = fat, 2 = dir, 3 = data
- 45 *007 01*(??) resp_mask db ? ; allowable responses (moot)
- 46 *008 01*(??) exterr db ? ; extended error number DOS >= 3 2/16/91 changed to byte
- 47 *009 01*(??) eclass db ? ; error class
- 48 *00A 01*(??) action db ? ; action recommendations
- 49 *00B 01*(??) locus db ? ; locus
- 50 *00C 01*(????????) nextdev dd ? ; next device pointer
- 51 *010 01*(????) attr dw ? ; device attribute
- 52 *012 01*(????) nxtfunc dw ? ; pointer to next strategy function
- 53 *014 01*(????) intfunc dw ? ; pointer to interrupt function
- 54 *016 01*(08*(??)) devname db 8 dup(?) ; device name
- 55 *01E 01*(??) dummy db ? ; terminating null
- 56 *01F CERR ENDS
- 57
- Turbo Assembler Version 2.0 02/17/91 12:40:52 Page 2
- criterr.asm
- CRITERR.ASM
- TRAP CRITICAL ERRORS FROM W/IN C
-
- 58 ; SEE DOS TECHNICAL REFERENCE FOR EXPLANATION OF CODES
- 59
- 60
- 61 ;;;;; BEGIN DATA SEGMENT ;;;;; USING SIMPLIFIED SEGMENT DIRECTIVES
- 62
- 63 0000 .DATA ; begin data segment
- 64 extrn __osmajor:byte ; operating system version
- 65 0000 00 _criterrtrap db 0 ; critical error flag 1=trapped, 0 = off
- 66 ;;;;; GLOBAL ;;;;;
- 67 public _cerr ; GLOBALS
- 68 0001 1F*(??) _cerr CERR <> ; CRITICAL ERROR STRUCTURE BLOCK
- 69
- 70 0020 .DATA? ; uninitialized data
- 71 0000 _oldint24vec label dword
- 72 0000 ???? _oldint24off dw ? ; static vector to int 24 before trap
- 73 0002 ???? _oldint24seg dw ? ;
- 74
- 75
- 76 ; PROCEDURE CRITERR( ONOFF )
- 77 ; SETS ALTERNATE CRITICAL ERROR HANDLER
- 78 ; USAGE: criterr( 1 ) to set, criterr( 0 ) to turn off
- 79
- 80 0004 .CODE ; begin code segment
- 81
- 82 0000 0000 savds dw 0 ; save proper data segment
- 83
- 84 public _criterr
- 85 0002 _criterr proc far
- 86 0002 55 push bp
- 87 0003 8B EC mov bp, sp
- 88 0005 56 push si
- 89 0006 57 push di
- 90 0007 8B 46 06 mov ax, p[bp] ; see if a 0 or 1 was passed
- 91 000A 85 C0 test ax, ax ; non zero?
- 92 000C 75 1C jne settrap ; 1, so set trap
- 93 000E removetrap:
- 94 000E 80 3E 0000r 01 cmp _criterrtrap, 1 ; see if installed
- 95 0013 75 45 jne done ; not installed, so return
- 96 0015 1E push ds
- 97 0016 C5 16 0000r lds dx, _oldint24vec ; restore original int 24 vector
- 98 001A B8 2524 mov ax, 2524h
- 99 001D CD 21 int 21h ; dos set vector function
- 100 001F 1F pop ds
- 101 0020 C6 06 0000r 00 mov _criterrtrap, 0 ; reset flag
- 102 0025 33 C0 xor ax, ax ; set return code
- 103 0027 EB 31 90 jmp done
- 104 002A settrap:
- 105 002A 80 3E 0000r 01 cmp _criterrtrap, 1 ; see if installed
- 106 002F 74 29 je done ; yes, so return (AX = 1)
- 107 0031 2E: 8C 1E 0000r mov cs:savds, ds ; move current data segment to savds
- 108 0036 06 push es
- 109 0037 B8 3524 mov ax,03524h ; save old vector to int 24
- 110 003A CD 21 int 021h
- 111 003C 89 1E 0000r mov _oldint24off,bx
- 112 0040 8C 06 0002r mov _oldint24seg,es
- 113 0044 07 pop es
- 114 0045 1E push ds
- Turbo Assembler Version 2.0 02/17/91 12:40:52 Page 3
- criterr.asm
- CRITERR.ASM
- TRAP CRITICAL ERRORS FROM W/IN C
-
- 115 0046 BA 0065r mov dx, offset cs:int_service ; load address of new routine
- 116 0049 8C C8 mov ax,cs
- 117 004B 8E D8 mov ds,ax
- 118 004D B8 2524 mov ax,02524h ; set it
- 119 0050 CD 21 int 021h
- 120 0052 1F pop ds
- 121 0053 C6 06 0000r 01 mov _criterrtrap, 1 ; set flag
- 122 0058 33 C0 xor ax, ax ;set return code
- 123
- 124 005A done:
- 125 005A 50 push ax ; save AX
- 126 005B 0E E8 008C 90 call far ptr _clrcriterr ; reset values
- 127 0060 58 pop ax
- 128 0061 5F pop di
- 129 0062 5E pop si
- 130 0063 5D pop bp
- 131 0064 CB ret ; return to caller, return code in AX
- 132
- 133
- 134 ;;;;; NEW CRITICAL ERROR HANDLER ;;;;;
- 135 ;;;;; SEE DOS TECHNICAL REFERENCE ;;;;;
- 136
- 137 0065 int_service: ;int 24 trap goes here
- 138 0065 55 push bp
- 139 0066 8B EC mov bp,sp ; set to critical stack frame
- 140 0068 53 push bx ; all used registers except AX must be
- 141 0069 51 push cx ; saved !!!!!
- 142 006A 52 push dx
- 143 006B 56 push si
- 144 006C 57 push di
- 145 006D 1E push ds
- 146 006E 06 push es
- 147 006F 9C pushf
- 148 0070 2E: 8E 1E 0000r mov ds,cs:savds ; reset ds to program's ds
- 149 0075 8B DF mov bx, di ; save DI
- 150 0077 BF 0001r mov di, offset _cerr ; set di to point to structure cerr
- 151 007A C6 05 01 mov ceflag[di], 1 ; set ceflag 2/16/91
- 152 007D 88 5D 01 mov cerrno[di], bl ; move to cerrno -- move byte only 2/16/91
- 153 0080 89 45 02 mov cerrtype[di],ax ; save error type/drive number
- 154 0083 A9 8000 test ax, 8000h ; char or block device
- 155 0086 8B D8 mov bx, ax
- 156 0088 75 10 jnz response ; char device, so skip
- 157 008A 80 C3 41 add bl, 'A' ; add letter A
- 158 008D 88 5D 04 mov drive[di], bl ; move drive over
- 159 0090 80 E7 06 and bh, 00000110b ; leave only bits 1 and 2
- 160 0093 D0 EF shr bh,1 ; shift it over 1
- 161 0095 88 7D 06 mov disk_area[di], bh ; save area of error
- 162 0098 8A FC mov bh, ah
- 163 009A response: ; determine response possibilities
- 164 009A 80 E7 01 and bh, 1 ; 2/16/91 this block moved from prev para.
- 165 009D 88 7D 05 mov read_wr[di], bh ; move read write flag
- 166 00A0 8A FC mov bh, ah
- 167 00A2 80 E7 38 and bh, 00111000b ; leave only bits 3-5
- 168 00A5 D0 EF shr bh,1
- 169 00A7 D0 EF shr bh,1
- 170 00A9 D0 EF shr bh,1 ; shift it over
- 171 00AB 88 7D 07 mov resp_mask[di],bh ; save response mask
- Turbo Assembler Version 2.0 02/17/91 12:40:52 Page 4
- criterr.asm
- CRITERR.ASM
- TRAP CRITICAL ERRORS FROM W/IN C
-
- 172 00AE move_dev_header: ; move device header block
- 173 00AE 1E push ds ; set up data registers
- 174 00AF 07 pop es
- 175 00B0 8B 5E 00 mov bx,[bp] ; load bp to get segment for device header
- 176 00B3 8E DB mov ds,bx ; si contains offset of device header
- 177 00B5 BF 000Dr mov di,offset _cerr.nextdev ; copy device header block
- 178 00B8 FC cld
- 179 00B9 B9 0009 mov cx,9
- 180 00BC F3> A5 rep movsw ; move 18 bytes of device header block
- 181 00BE 06 push es
- 182 00BF 1F pop ds ; restore data registers
- 183
- 184 ; now check for DOS version
- 185 00C0 33 C0 xor ax,ax ; return code ignore for dos < 3
- 186 00C2 80 3E 0000e 03 cmp __osmajor,3 ; dos >= 3?
- 187 00C7 7C 18 jl doneint ; no
- 188 ; prepare to get extended error
- 189 00C9 BB 0000 mov bx, 0
- 190 00CC B4 59 mov ah, 59h ; get dos extended error
- 191 00CE CD 21 int 21h ; call dos
- 192 00D0 BF 0001r mov di, offset _cerr; set di to point to cerr structure
- 193 00D3 88 45 08 mov exterr[di], al ; error code -- move byte only 2/16/91
- 194 00D6 88 7D 09 mov eclass[di], bh ; error class
- 195 00D9 88 5D 0A mov action[di], bl ; action
- 196 00DC 88 6D 0B mov locus[di], ch ; locus
- 197 00DF B0 03 mov al, 3 ; return fail code
- 198 00E1 doneint:
- 199 00E1 9D popf
- 200 00E2 07 pop es
- 201 00E3 1F pop ds
- 202 00E4 5F pop di
- 203 00E5 5E pop si
- 204 00E6 5A pop dx
- 205 00E7 59 pop cx
- 206 00E8 5B pop bx
- 207 00E9 5D pop bp ; restore stack frame
- 208 00EA CF iret ; return from interrupt
- 209 00EB _criterr endp
- 210
- 211 ;;;;; FUNCTION TO CLEAR CRITICAL ERROR STATUS ;;;;;
- 212
- 213 ;;;;; USAGE: clrcriterr()
- 214
- 215 public _clrcriterr
- 216 00EB _clrcriterr proc far ; function to clear critical error number
- 217
- 218 00EB 55 push bp
- 219 00EC 8B EC mov bp,sp
- 220 00EE 57 push di
- 221 00EF 1E push ds
- 222 00F0 07 pop es
- 223 00F1 33 C0 xor ax,ax ; zero entire structure
- 224 00F3 BF 0001r mov di, offset _cerr
- 225 00F6 B9 001F mov cx, size _cerr ; get size of entire block
- 226 00F9 F3> AA rep stosb
- 227 00FB 5F pop di
- 228 00FC 5D pop bp
- Turbo Assembler Version 2.0 02/17/91 12:40:52 Page 5
- criterr.asm
- CRITERR.ASM
- TRAP CRITICAL ERRORS FROM W/IN C
-
- 229 00FD CB ret
- 230 00FE _clrcriterr endp
- 231
- 232 end
- Turbo Assembler Version 2.0 02/17/91 12:40:52 Page 6
- Symbol Table
- CRITERR.ASM
-
-
-
- Symbol Name Type Value
-
- ??DATE Text "02/17/91"
- ??FILENAME Text "criterr "
- ??TIME Text "12:40:51"
- ??VERSION Number 0200
- @CODE Text CRITERR_TEXT
- @CODESIZE Text 1
- @CPU Text 0101H
- @CURSEG Text CRITERR_TEXT
- @DATA Text DGROUP
- @DATASIZE Text 1
- @FILENAME Text CRITERR
- @MODEL Text 5
- @WORDSIZE Text 2
- DONE Near CRITERR_TEXT:005A
- DONEINT Near CRITERR_TEXT:00E1
- I8086L Text
- INT_SERVICE Near CRITERR_TEXT:0065
- LCODE Number 0001
- LDATA Number 0001
- MOVE_DEV_HEADER Near CRITERR_TEXT:00AE
- P Number 0006
- REMOVETRAP Near CRITERR_TEXT:000E
- RESPONSE Near CRITERR_TEXT:009A
- SAVDS Word CRITERR_TEXT:0000
- SETTRAP Near CRITERR_TEXT:002A
- _CERR (_cerr) Struct DGROUP:0001 CERR
- _CLRCRITERR (_clrcriterr) Far CRITERR_TEXT:00EB
- _CRITERR (_criterr) Far CRITERR_TEXT:0002
- _CRITERRTRAP Byte DGROUP:0000
- _OLDINT24OFF Word DGROUP:0000
- _OLDINT24SEG Word DGROUP:0002
- _OLDINT24VEC Dword DGROUP:0000
- __OSMAJOR (__osmajor) Byte DGROUP:---- Extern
-
- Structure Name Type Offset
-
- CERR
- CEFLAG Byte 0000
- CERRNO Byte 0001
- CERRTYPE Word 0002
- DRIVE Byte 0004
- READ_WR Byte 0005
- DISK_AREA Byte 0006
- RESP_MASK Byte 0007
- EXTERR Byte 0008
- ECLASS Byte 0009
- ACTION Byte 000A
- LOCUS Byte 000B
- NEXTDEV Dword 000C
- ATTR Word 0010
- NXTFUNC Word 0012
- INTFUNC Word 0014
- DEVNAME Byte 0016
- DUMMY Byte 001E
- Turbo Assembler Version 2.0 02/17/91 12:40:52 Page 7
- Symbol Table
- CRITERR.ASM
-
-
-
- Groups & Segments Bit Size Align Combine Class
-
- CRITERR_TEXT 16 00FE Word Public CODE
- DGROUP Group
- _BSS 16 0004 Word Public BSS
- _DATA 16 0020 Word Public DATA
-